package com.example.smartcity4.math;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.ImageView;
import android.widget.MediaController;
import android.widget.TextView;

import com.example.smartcity4.MainActivity;
import com.example.smartcity4.R;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.charts.HorizontalBarChart;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.formatter.IndexAxisValueFormatter;

import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class MathActivity extends AppCompatActivity {
    private TextView title;
    private ImageView left;
    private ImageView more;
    private BarChart barChart;
    private LineChart LineChart;
    private PieChart PieChart;
    private HorizontalBarChart HorizontalBarChart;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_math);
        initView();
    }

    private void initView() {

        title = findViewById(R.id.title);
        left = findViewById(R.id.left);
        more = findViewById(R.id.more);
        barChart = findViewById(R.id.barChart);
        LineChart = findViewById(R.id.LineChart);
        PieChart = findViewById(R.id.PieChart);
        HorizontalBarChart = findViewById(R.id.HorizontalBarChart);
        initData();

    }

    private void initData() {
        PieChart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivityForResult(new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI),99);
            }
        });

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
    }

    private void setBar() {
        List<BarEntry> barEntries = new ArrayList<>();
        barEntries.add(new BarEntry(0, 2));
        barEntries.add(new BarEntry(1, 4));
        barEntries.add(new BarEntry(2, 3));
        barEntries.add(new BarEntry(3, 5));
        List<BarEntry> barEntries1 = new ArrayList<>();
        barEntries1.add(new BarEntry(0, 1));
        barEntries1.add(new BarEntry(1, 3));
        barEntries1.add(new BarEntry(2, 6));
        barEntries1.add(new BarEntry(3, 5));
        BarDataSet barDataSet = new BarDataSet(barEntries, "男");
        BarDataSet barDataSet1 = new BarDataSet(barEntries1, "女");
        barDataSet.setColor(Color.RED);
        barDataSet1.setColor(Color.BLUE);
        BarData barData = new BarData(barDataSet, barDataSet1);
        barChart.setData(barData);
        barChart.requestLayout();
        barChart.notifyDataSetChanged();

        barData.setBarWidth(0.4f);
        XAxis xAxis = barChart.getXAxis();
        xAxis.setAxisMaximum(5);
        xAxis.setAxisMinimum(-1);
        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
        xAxis.setValueFormatter(new IndexAxisValueFormatter(Arrays.asList("如何汇...", "31省...", "拒收现...", "首季经...")));
        barChart.groupBars(-0.5f,0.2f,0);
    }
}